************************
 version 16
set seed 123456
 
use "Infoseeking_pooled" , clear

***Generate Overconfidence variables

* 1) Median split

sum overconfid, d


//median is 3.so next, we generate dummy var taking value 1 if observation has OC above 3 and 0, otherwise

gen OC_M =1 if overconfid>3
replace OC_M=0 if overconfid<=3 & OC_M==.
 lab var OC_M "OC_R"
 
 
 gen OC_MxES = OC_M*advisor
lab var  OC_MxES  "OC_R X Extension agent" 

***2) Continuous overconfidence measure

summarize overconfid /*standardizing overconfidence using Z-scores*/
generate overconfid_N = (overconfid - r(mean)) / r(sd)
lab var overconfid_N "Overconfidence" 


gen OCXadvisor= overconfid_N*advisor
lab var OCXadvisor "OC X Extension agent"


gen ableXadvisor = ownscore_tot*advisor
lab var ableXadvisor "Ability X extension"

lab var confidence_self "Percieved ability"

lab var  ownscore_tot "Actual performance"

***Generating other variables  (dummy performance indicator above and below 50% correct answers)

gen perform_D=1 if  ownscore_tot >=5
replace perform_D=0 if perform_D==.
lab var perform_D "Actual performance"


***Histogram overconfidence by task familiarity (Figure 2)***
 
  histogram overconfid, by (familar, graphregion(color(white)) bgcolor(white)) color(ltblue) start(-10) addplot(pci 0 0 .5 0) normal  

  
*********Overconfidence and seeking (Figure 3)*****
twoway (histogram n_osource if OC_M==1,  color(blue%30)) ///        
       (histogram n_osource if OC_M==0, color(black%60)),    ///   
         graphregion(color(white)) legend(order(1 "Overconfident" 2 "Non-overconfident" ))  

		 
		 
***********Histogram actual and percieved ability (Appendix B1 and B2)****
 histogram ownscore_tot, graphregion(color(white)) bgcolor(white) color(ltblue) normal 
 
  graph export "ability.eps", as(eps) name("Graph") preview(off) replace

 sum ownscore_tot 
 
  histogram confidence_self, graphregion(color(white)) bgcolor(white) color(ltblue) normal

   graph export "percieved_ability.eps", as(eps) name("Graph") preview(off) replace
   
sum confidence_self




**************Begin main results OC***************
global Xlist " age  sex educ_formal iqub LOC farmsize farmexp TLU gtrust2 Risk "


                ***OC AND SEEKING MAIN RESULT***
				
				   *dumy OC measure (Table 4)*



qui reg  n_osource OC_M , vce (cluster got)

outreg2 using OC_Main.xls, lab replace  addtext(Controls, NO, Village FE, NO)

ereturn list rmse //these are to compare OLS RSME with random forest RSME


qui reg n_osource OC_M  advisor OC_MxES ownscore_tot , vce (cluster got)

outreg2 using OC_Main.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor) addtext(Controls, NO, Village FE, NO)

ereturn list rmse


qui reg n_osource OC_M  advisor OC_MxES ownscore_tot  familar $Xlist V2-V10 ,  vce (cluster got)

outreg2 using OC_Main.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor) drop( familar $Xlist V2-V10 ) addtext(Controls, YES, Village FE, YES)

ereturn list rmse
              *** cont OC measure

qui reg n_osource overconfid_N, vce (cluster got)

outreg2 using OC_Main.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor)  addtext(Controls, NO, Village FE, NO)

ereturn list rmse


qui reg n_osource overconfid_N  perform_D advisor OCXadvisor,  vce (cluster got)

outreg2 using OC_Main.xls, lab append sortvar(OC_M  overconfid_N ownscore_tot perform_D advisor OC_MxES OCXadvisor) addtext(Controls, NO, Village FE, NO)

ereturn list rmse


qui reg n_osource overconfid_N   perform_D advisor OCXadvisor familar $Xlist V2-V10 ,vce (cluster got)

outreg2 using OC_Main.xls, lab append sortvar(OC_M overconfid_N ownscore_tot perform_D advisor OC_MxES OCXadvisor) drop( familar $Xlist V2-V10 ) addtext(Controls, YES, Village FE, YES) 

ereturn list rmse
		  
	  /////////////////////////end main results OC////////////////////
			  
			  
	
	
	
	////////////////////beging appendix OC/////////////////////////
	

          ****APPENDIX 3: cont and dummy OC NBR**


qui nbreg n_osource OC_M ,  vce (cluster got)

outreg2 using OC_App.xls, lab replace  addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource OC_M  advisor OC_MxES ownscore_tot , vce (cluster got)

outreg2 using OC_App.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor) addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource OC_M  advisor OC_MxES ownscore_tot  familar $Xlist V2-V10 , vce (cluster got)

outreg2 using OC_App.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor) drop( familar $Xlist V2-V10 ) addtext(Controls, YES, Village FE, YES)

              *** cont OC measure

qui nbreg n_osource overconfid_N,  vce (cluster got)

outreg2 using OC_App.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor)  addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource overconfid_N  perform_D advisor OCXadvisor, vce (cluster got)

outreg2 using OC_App.xls, lab append sortvar(OC_M  overconfid_N ownscore_tot perform_D advisor OC_MxES OCXadvisor) addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource overconfid_N   perform_D advisor OCXadvisor familar $Xlist V2-V10 , vce (cluster got)

outreg2 using OC_App.xls, lab append sortvar(OC_M overconfid_N ownscore_tot perform_D advisor OC_MxES OCXadvisor) drop( familar $Xlist V2-V10 ) addtext(Controls, YES, Village FE, YES) 
				

				*****************consistent OC sample***********
		
	preserve

gen movers=1 if Itot==1 & Itot_raven==0
replace movers=1 if Itot_raven==1 & Itot==0
drop if movers==1

cap drop OC_MxES
gen OC_MxES = OC_M*advisor
lab var OC_MxES "OC_R X Extension agent"




                *** Appendix 4: consistent sample; OLS
				

qui reg n_osource OC_M ,  vce(cluster got)
outreg2 using OC_app_OLS.xls, lab replace  addtext(Controls, NO, Village FE, NO)


qui reg n_osource OC_M  advisor OC_MxES ownscore_tot, vce(cluster got)
outreg2 using OC_app_OLS.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor) addtext(Controls, NO, Village FE, NO)


qui reg n_osource OC_M  advisor OC_MxES ownscore_tot  familar $Xlist V2-V10 , vce(cluster got)
outreg2 using OC_app_OLS.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor) drop( familar $Xlist V2-V10 ) addtext(Controls, YES, Village FE, YES)

              *** cont OC measure

qui reg n_osource overconfid_N,   vce(cluster got)
outreg2 using OC_app_OLS.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor)  addtext(Controls, NO, Village FE, NO)


qui reg n_osource overconfid_N  perform_D advisor OCXadvisor,  vce(cluster got)
outreg2 using OC_app_OLS.xls, lab append sortvar(OC_M  overconfid_N ownscore_tot perform_D advisor OC_MxES OCXadvisor) addtext(Controls, NO, Village FE, NO)


qui reg n_osource overconfid_N   perform_D advisor OCXadvisor familar $Xlist V2-V10,  vce(cluster got)
outreg2 using OC_app_OLS.xls, lab append sortvar(OC_M overconfid_N ownscore_tot perform_D advisor OC_MxES OCXadvisor) drop( familar $Xlist V2-V10 ) addtext(Controls, YES, Village FE, YES) 





                **APPENDIX 5: consistent sample; NBR

qui nbreg n_osource OC_M ,  vce (cluster got)
outreg2 using OC_App_NBR.xls, lab replace  addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource OC_M  advisor OC_MxES ownscore_tot , vce (cluster got)
outreg2 using OC_App_NBR.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor) addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource OC_M  advisor OC_MxES ownscore_tot  familar $Xlist V2-V10 , vce (cluster got)
outreg2 using OC_App_NBR.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor) drop( familar $Xlist V2-V10 ) addtext(Controls, YES, Village FE, YES)

              *** cont OC measure

qui nbreg n_osource overconfid_N,  vce (cluster got)
outreg2 using OC_App_NBR.xls, lab append sortvar(OC_M  overconfid_N  ownscore_tot perform_D advisor OC_MxES OCXadvisor)  addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource overconfid_N  perform_D advisor OCXadvisor, vce (cluster got)
outreg2 using OC_App_NBR.xls, lab append sortvar(OC_M  overconfid_N ownscore_tot perform_D advisor OC_MxES OCXadvisor) addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource overconfid_N   perform_D advisor OCXadvisor familar $Xlist V2-V10 , vce (cluster got)
outreg2 using OC_App_NBR.xls, lab append sortvar(OC_M overconfid_N ownscore_tot perform_D advisor OC_MxES OCXadvisor) drop( familar $Xlist V2-V10 ) addtext(Controls, YES, Village FE, YES) 

restore
	
		
		////////////////////end appendix OC/////////////////////////
		
		
preserve



* Random Forest
*code from Schonlau and Zou: The Random Forest Algorithm for Statistical Learning

drop if n_osource==. //because RF doesn't tolerate missing values, I remove the pure control group where there was no seeking option.

set seed 123456
gen u = uniform()
sort u, stable

 ** tuning the number of iterations/sub-trees
gen out_of_bag_error1 = .
gen validation_error = .
gen iter1 = .
local j = 0

forvalues i = 10(5)500 {
    local   j = `j' +1
	rforest n_osource OC_M  advisor OC_MxES ownscore_tot  familar  age  sex educ_formal iqub LOC farmsize farmexp TLU gtrust2 Risk in 1/768, ///
	type(reg) iter(`i') numvars (1)
	qui replace iter1 = `i' in `j'
	qui replace out_of_bag_error1 = `e(OOB_Error)' in `j'
	predict p in 769/1280
	qui replace validation_error = `e(RMSE)' in `j'
	drop p
}


label var out_of_bag_error1 "Out of Bag Error"
label var iter1 "Iterations"
label var validation_error "Validation RMSE"

scatter out_of_bag_error1 iter1, mcolor(grey) msize(tiny) msymbol(X) || ///
scatter validation_error iter1, mcolor(black%60) msize(tiny) msymbol(S) graphregion(color(white))
graph export "iteration.eps", as(eps) name("Graph")  replace
   
   
**tuning the number of variables that give the lowest validation error***

gen oob_error = .
gen nvars = .
gen val_error = .
local j = 0

forvalues i =1(1)15{
    local j = `j' + 1
	rforest n_osource OC_M  advisor OC_MxES ownscore_tot familar  age  sex educ_formal iqub LOC farmsize farmexp TLU gtrust2 Risk in 1/768, ///
	type(reg) iter(500) numvars (`i')
	qui replace nvars = `i' in `j'
	qui replace oob_error = `e(OOB_Error)' in `j'
	predict p in 769/1280
	qui replace val_error = `e(RMSE)' in `j'
	drop p
}

lab var oob_error "Out of Bag Error"
lab var val_error "Validation RMSE"
lab var nvars "Number of Variables Randomly Selected at Each Split"

scatter oob_error nvars, mcolor(grey) msize(small) msymbol(T)|| ///
scatter val_error nvars, mcolor(black%60) msize(small) msymbol(D) graphregion(color(white))
   graph export "variables.eps", as(eps) name("Graph") replace

  

**** final model


	rforest n_osource OC_M  advisor OC_MxES ownscore_tot familar  age  sex educ_formal iqub LOC farmsize farmexp TLU gtrust2 Risk in 1/768, ///
	type(reg) iter(500) numvars (4)
	
ereturn list OOB_Error

predict prf in 769/1280
ereturn list RMSE

//variable importance plot

 matrix importance1 = e(importance)
 svmat importance1
gen importid1=""

local mynames : rownames importance1
local k : word count `mynames'
if `k' >_N {
set obs `k'

 }
 
 forvalues i = 1(1)`k' {
 local aword : word `i' of `mynames'
 local alabel : variable label `aword'
if ("`alabel'"!="") qui replace importid1= "`alabel'" in `i'
else qui replace importid1= "`aword'" in `i'

 }

 graph hbar (mean) importance1 if importance1>.5, over(importid1, sort(1) ///
 label(labsize(2))) ytitle(Importance) graphregion(color(white)) bar(1, fcolor(ltblue)) 
 
    graph export "var_importance.eps", as(eps) name("Graph") replace


***Compare with OLS prediction in out of smaple

reg n_osource OC_M  advisor OC_MxES ownscore_tot familar  age  sex educ_formal iqub LOC farmsize farmexp TLU gtrust2 Risk in 1/768 
predict seek_OLS in 769/1280

ereturn list rmse // 1.530 this gives the RMSE for the training data

//to get the RMSE for the testing data, we do the following

gen diff_sqr = (n_osource - seek_OLS)^2
summarize diff_sqr // We get mean square error of  2.198856

display sqrt( 2.198856 ) // the RMSE on test data becomes 1.475 




restore		
		
////////////////////////////////////////////////////////////////////////	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
					

////////////Quality, trust and seeking//////////////////////////

***First separately by source type****
***************************************
****Extension source*********
gen qualityEA =1 if trustEA==4
replace qualityEA=0 if trustEA== 1 & qualityEA==.
lab var qualityEA "High-quality"

gen qualEAXOC = qualityEA*overconfid_N
lab var qualEAXOC "OC X High-quality"

			 

				 
********************************************
***************Peer source*****************
gen qualityPF =1 if trustPF==4
replace qualityPF=0 if trustPF== 1 & qualityPF==.
lab var qualityPF "High-quality"


gen qualityPFXOC = qualityPF*overconfid_N
lab var qualityPFXOC "OC X High-quality"
               ****

*************POOLING DATA OVER HIGHQUALITY********************
/*Here, I pool the data over both source types and then use interaction terms instead of two separate tables by the advisor type*/


gen HQ=1 if qualityEA ==1| qualityPF ==1
replace HQ=0 if qualityEA ==0| qualityPF ==0 & HQ==.
lab var HQ "High quality"

gen OC_ES_HQ = HQ*advisor*overconfid_N
lab var OC_ES_HQ "OC X ES X High quality" 

gen OC_HQ = overconfid_N*HQ
lab var OC_HQ "OC X High quality"
********

gen OC_ES = overconfid_N*advisor
lab var OC_ES "OC X Extension agent"
***


*******with dummy OC*********


gen ES_HQ= advisor*HQ
lab var ES_HQ "EA X High quality"

gen OC_MxHQ= OC_M*HQ
lab var  OC_MxHQ "OC_R X High quality"


gen OC_MxEA_HQ = OC_M*advisor
lab var  OC_MxEA_HQ "OC_R X Extension agent"


gen OC_MxHQxEA = OC_M*HQ*advisor
lab var  OC_MxHQxEA "OC_R X EA X High quality"



gen nudgeEAT=1 if  trustEA==6
replace nudgeEAT=0 if  trustEA==5


gen nudgeEAUT=1 if  trustEA==3
replace nudgeEAUT=0 if  trustEA==2


           *******************
 gen nudgePFT=1 if  trustPF==6
replace nudgePFT=0 if  trustPF==5


gen nudgePFUT=1 if  trustPF==3
replace nudgePFUT=0 if  trustPF==2

*********************
gen trained_source=1 if nudgeEAT==1 | nudgePFT==1 | nudgeEAT==0| nudgePFT==0
replace trained_source=0 if nudgeEAUT==1 |nudgeEAUT==0 | nudgePFUT==1 | nudgePFUT==0 & trained_source==.


*tab trained_source

****generating HIGH TRUST NUDGE variable pooled data****
gen hightrust = 1 if nudgeEAT==1 | nudgePFT==1 | nudgeEAUT==1| nudgePFUT==1
replace hightrust=0 if nudgeEAT==0 | nudgePFT==0 | nudgeEAUT==0| nudgePFUT==0 & hightrust==.

lab var hightrust "High trust"
*tab hightrust


gen OC_EA_T = overconfid_N*advisor
lab var  OC_EA_T "OC X Extension agent"

gen OC_trust = overconfid_N*hightrust
lab var  OC_trust "OC X High trust"


gen OC_EA_trust= overconfid_N*advisor*hightrust
lab var OC_EA_trust "OC X ES X High trust"


******Dummy OC*********
**WITH DUMMY OC***********

gen OC_Mxtrust = OC_M*hightrust
lab var  OC_Mxtrust "OC_R X High trust"


gen OC_MxEA = OC_M*advisor
lab var  OC_MxEA "OC_R X Extension agent"


gen OC_MxtrustxEA = OC_M*hightrust*advisor
lab var  OC_MxtrustxEA "OC_R X EA X High trust"









******OLS regression Quality and Trust (Table 5)****


qui reg n_osource HQ ,   vce(cluster got) 

outreg2 using HQ_HT_OLS.xls, lab replace addtext(Controls, NO, Village FE, NO) 


qui reg n_osource HQ OC_M advisor  ES_HQ  OC_MxHQ OC_MxEA_HQ OC_MxHQxEA,  vce(cluster got) 

outreg2 using HQ_HT_OLS.xls, lab append addtext(Controls, NO, Village FE, NO) keep(HQ OC_M advisor OC_MxHQ)   sortvar(HQ  hightrust advisor OC_M  OC_MxHQ  OC_Mxtrust)

qui reg n_osource HQ OC_M advisor ES_HQ  OC_MxHQ OC_MxEA_HQ OC_MxHQxEA  ownscore_tot familar $Xlist V2-V10,  vce(cluster got) 

outreg2 using HQ_HT_OLS.xls, lab append addtext(Controls, YES, Village FE, YES) keep(HQ OC_M advisor OC_MxHQ)   sortvar (HQ  hightrust advisor OC_M  OC_MxHQ  OC_Mxtrust)


***Trust

  
qui reg n_osource hightrust , vce(cluster got) 

outreg2 using HQ_HT_OLS.xls, lab append addtext(Controls, NO, Village FE, NO)


qui reg n_osource hightrust OC_M advisor OC_MxEA EA_trust OC_Mxtrust OC_MxtrustxEA ,   vce(cluster got) 
		 
outreg2 using HQ_HT_OLS.xls, lab append addtext(Controls, NO, Village FE, NO) keep( hightrust OC_M advisor OC_Mxtrust)   sortvar (HQ  high  trust advisor OC_M  OC_MxHQ  OC_Mxtrust)


qui reg n_osource hightrust OC_M advisor OC_MxEA EA_trust OC_Mxtrust OC_MxtrustxEA ownscore_tot trained_source familar $Xlist V2-V10,   vce(cluster got) 
		 
outreg2 using HQ_HT_OLS.xls, lab append addtext(Controls, YES, Village FE, YES) keep( hightrust OC_M advisor OC_Mxtrust)  sortvar (HQ  hightrust advisor OC_M  OC_MxHQ  OC_Mxtrust)

		

		
		
		

***checking for equality of coefficients for HQ and HT

nbreg n_osource HQ

est store r1


nbreg n_osource hightrust

est store r2 


suest r1 r2 

test [r1_n_osource]HQ - [r2_n_osource]hightrust=0




//////////////////END MAIN ANALYSES///////////////////////////////




////////////////BEGIN APPENDIX//////////////////////////


 
*******Appendix 6:  NBR--dummy ****

**QUALITY
qui nbreg n_osource HQ , vce (cluster got) 
outreg2 using HQ_HT_NBR.xls, lab replace addtext(Controls, NO, Village FE, NO) 


qui nbreg n_osource HQ OC_M advisor ES_HQ  OC_MxHQ OC_MxEA_HQ OC_MxHQxEA, vce (cluster got) 
outreg2 using HQ_HT_NBR.xls, lab append addtext(Controls, NO, Village FE, NO) keep(HQ OC_M advisor OC_MxHQ) sortvar (HQ  hightrust advisor OC_M  OC_MxHQ  OC_Mxtrust)



qui nbreg n_osource HQ OC_M advisor ES_HQ  OC_MxHQ OC_MxEA_HQ OC_MxHQxEA  ownscore_tot familar $Xlist V2-V10, vce (cluster got) 
outreg2 using HQ_HT_NBR.xls, lab append addtext(Controls, YES, Village FE, YES) keep(HQ OC_M advisor OC_MxHQ) sortvar (HQ  hightrust advisor OC_M  OC_MxHQ  OC_Mxtrust)



***TRUST
qui nbreg n_osource hightrust , vce (cluster got)
outreg2 using HQ_HT_NBR.xls, lab append addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource hightrust OC_M advisor OC_MxEA EA_trust OC_Mxtrust OC_MxtrustxEA , vce (cluster got) 
outreg2 using HQ_HT_NBR.xls, lab append addtext(Controls, NO, Village FE, NO) keep(hightrust OC_M advisor OC_Mxtrust) sortvar (HQ  hightrust advisor OC_M  OC_MxHQ  OC_Mxtrust)



qui nbreg n_osource hightrust OC_M advisor OC_MxEA EA_trust OC_Mxtrust OC_MxtrustxEA ownscore_tot trained_source familar $Xlist V2-V10, vce (cluster got)	 
outreg2 using HQ_HT_NBR.xls, lab append addtext(Controls, YES, Village FE, YES) keep(hightrust OC_M advisor OC_Mxtrust) sortvar (HQ  hightrust advisor OC_M  OC_MxHQ  OC_Mxtrust)




 
****Appendix 7: cont. OC


***OLS

*** Quality

qui reg n_osource HQ, vce(cluster got)
outreg2 using HQ_HT_app_OLS.xls, lab replace addtext(Controls, NO, Village FE, NO) 



qui reg n_osource HQ overconfid_N advisor OC_HQ ES_HQ OC_ES OC_ES_HQ, vce(cluster got)
outreg2 using HQ_HT_app_OLS.xls, lab append keep( HQ overconfid_N advisor OC_HQ) addtext(Controls, NO, Village FE, NO) 


qui reg n_osource HQ overconfid_N advisor OC_HQ ES_HQ OC_ES OC_ES_HQ perform_D familar $Xlist V2-V10, vce(cluster got)
outreg2 using HQ_HT_app_OLS.xls, lab append addtext(Controls, YES, Village FE, YES) keep( HQ overconfid_N advisor OC_HQ) sortvar (HQ  hightrust advisor overconfid_N  OC_HQ  OC_trust)


*** Trust

qui reg n_osource hightrust , vce(cluster got)
outreg2 using HQ_HT_app_OLS.xls, lab append addtext(Controls, NO, Village FE, NO)


qui reg n_osource hightrust overconfid_N advisor OC_EA_T OC_trust  EA_trust OC_EA_trust,vce(cluster got)
outreg2 using HQ_HT_app_OLS.xls, lab append keep(hightrust overconfid_N advisor  OC_trust)  addtext(Controls, NO, Village FE, NO)


qui reg n_osource hightrust overconfid_N advisor OC_EA_T OC_trust  EA_trust OC_EA_trust trained_source perform_D familar $Xlist V2-V10, vce(cluster got) 
outreg2 using HQ_HT_app_OLS.xls, lab append addtext(Controls, YES, Village FE, YES) keep(hightrust overconfid_N advisor  OC_trust)  sortvar (HQ  hightrust advisor overconfid_N  OC_HQ  OC_trust)
		
******************





***Appendix 8: NBR cont. OC****


*** Quality

qui nbreg n_osource HQ , vce (cluster got) 
outreg2 using HQ_HT_app_NBR.xls, lab replace addtext(Controls, NO, Village FE, NO) 



qui nbreg n_osource HQ overconfid_N advisor OC_HQ ES_HQ OC_ES OC_ES_HQ, vce (cluster got) 
outreg2 using HQ_HT_app_NBR.xls, lab append keep( HQ overconfid_N advisor OC_HQ) addtext(Controls, NO, Village FE, NO) 


qui nbreg n_osource HQ overconfid_N advisor OC_HQ ES_HQ OC_ES OC_ES_HQ perform_D familar $Xlist V2-V10, vce (cluster got) 
outreg2 using HQ_HT_app_NBR.xls, lab append addtext(Controls, YES, Village FE, YES) keep( HQ overconfid_N advisor OC_HQ) sortvar (HQ  hightrust advisor overconfid_N  OC_HQ  OC_trust)


*** Trust

qui nbreg n_osource hightrust , vce (cluster got)
outreg2 using HQ_HT_app_NBR.xls, lab append addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource hightrust overconfid_N advisor OC_EA_T OC_trust  EA_trust OC_EA_trust, vce (cluster got)
outreg2 using HQ_HT_app_NBR.xls, lab append keep(hightrust overconfid_N advisor  OC_trust)  addtext(Controls, NO, Village FE, NO)


qui nbreg n_osource hightrust overconfid_N advisor OC_EA_T OC_trust  EA_trust OC_EA_trust trained_source perform_D familar $Xlist V2-V10, vce (cluster got)
outreg2 using HQ_HT_app_NBR.xls, lab append addtext(Controls, YES, Village FE, YES) keep(hightrust overconfid_N advisor  OC_trust)  sortvar (HQ  hightrust advisor overconfid_N  OC_HQ  OC_trust)







///////////////////////////Begin Efficiency analyses//////////////////////

******************************

***********SFA *************

*********************************

gen log_totscore= log(n_score+0.001)
lab var log_totscore "log total scores"

gen log_input_source = log(n_osource+0.000001) /*I add a small number so that the zero observations in my sample can also be transformed otherwise they get missing values*/
lab var log_input_source "log Source"

gen input_self = 10-n_osource
gen log_inpur_self=log(input_self+0.000001)
lab var log_inpur_self "log Farmer"




   

  
 ****MAIN RESULT REPORTED IN TABLE 9***
   
   

  qui frontier log_totscore log_input_source log_inpur_self, dist(exponential) uhet(OC_M, noconstant) vhet() 

outreg2 using efftrust.xls, lab replace addtext(Controls, NO, Village FE, NO) 
/*
estimates store efftOC
 
predict efftOC, te 

sum efftOC */
***trust only

  qui frontier log_totscore log_input_source log_inpur_self, dist(exponential) uhet(hightrust, noconstant) vhet() 

outreg2 using efftrust.xls, lab append addtext(Controls, NO, Village FE, NO) 
/*
estimates store efftTR
 
predict efftTR, te 

sum efftTR*/

**ES only

 qui frontier log_totscore log_input_source log_inpur_self, dist(exponential) uhet(advisor, noconstant) vhet() 

outreg2 using efftrust.xls, lab append addtext(Controls, NO, Village FE, NO) 

/*
estimates store efftES
 
predict efftES, te 

sum efftES */

***OC AND TRUST ONLY
qui frontier log_totscore log_input_source log_inpur_self, dist(exponential) uhet(OC_M hightrust  , noconstant) vhet() 

outreg2 using efftrust.xls, lab append addtext(Controls, NO, Village FE, NO) drop(familar trained_source $Xlist V2-V10) sortvar(log_input_source log_inpur_self OC_M hightrust  advisor )

*estimates store efftOCT
 
*predict efftOCT, te 

*sum efftOCT
***OC and Extension
qui frontier log_totscore log_input_source log_inpur_self, dist(exponential) uhet(OC_M advisor, noconstant) vhet() 

outreg2 using efftrust.xls, lab append addtext(Controls, NO, Village FE, NO) drop(familar trained_source $Xlist V2-V10) sortvar(log_input_source log_inpur_self OC_M hightrust  advisor )


*estimates store efftOCES
 
*predict efftOCES, te 

*sum efftOCES

**All but no other controls
qui frontier log_totscore log_input_source log_inpur_self, dist(exponential) uhet(OC_M hightrust advisor, noconstant) vhet() 

outreg2 using efftrust.xls, lab append addtext(Controls, NO, Village FE, NO) drop(familar trained_source $Xlist V2-V10) sortvar(log_input_source log_inpur_self OC_M hightrust  advisor )

*drop efftAL
*estimates store efftAL
 
*predict efftAL, te 

*sum efftAL 
***** with all controls

 qui frontier log_totscore log_input_source log_inpur_self, dist(exponential) uhet(OC_M hightrust advisor familar trained_source confidence_advisor OC_MxEA OC_Mxtrust OC_MxtrustxEA  $Xlist V2-V10, noconstant) vhet() 

outreg2 using efftrust.xls, lab append addtext(Controls, YES, Village FE, YES) drop( familar trained_source confidence_advisor $Xlist V2-V10) sortvar(log_input_source log_inpur_self OC_M hightrust  advisor OC_MxEA OC_Mxtrust OC_MxtrustxEA)

/*to estimate the base category average efficiency*/
*drop efftALL

estimates store efftALL
 
predict efftALL, te 

sum efftALL

sum efftALL if OC_M==0

sum efftALL if hightrust==0

sum efftALL if advisor==0


///////////////////////End of Efficiency analyses/////////////////////

  
  
  
  
  
 ////////////////////////Begin More appendix//////////////////////
  


*****to see if results are larger fo those with advisors in response to reviewer's suggestion (Appendix 1)***

gen Control = 1 if Tgroups==1
replace Control = 0 if Tgroups >1

ttest n_score, by(Control)








**********Determinnats of overconfidence (APPENDIX 2)***

qui reg overconfid_N familar $Xlist ,vce (cluster got)
outreg2 using determinants.xls, drop(familar V2-V10) addtext( Task familiarity, YES, Village FE, NO) sortvar (farmsize Risk ) lab replace

qui reg overconfid_N familar $Xlist V2-V10, vce (cluster got)
outreg2 using determinants.xls, drop(familar V2-V10) addtext( Task familiarity, YES, Village FE, YES) sortvar (farmsize Risk) lab append
*********

qui logit OC_M familar $Xlist ,vce (cluster got)
outreg2 using determinants.xls, drop(familar V2-V10) addtext(Task familiarity, YES,  Village FE, NO) sortvar (farmsize Risk ) lab append

qui logit OC_M familar $Xlist V2-V10, vce (cluster got)
outreg2 using determinants.xls, drop(familar V2-V10) addtext( Task familiarity, YES, Village FE, YES) sortvar (farmsize Risk) lab append

////////////////////////////END APPENDIX//////////////////////////////////////////














